package com.orange.core.pojo.entity.coupon;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.orange.core.pojo.entity.IIntIdModel;
import com.orange.core.pojo.entity.IOperatorModel;
import com.orange.core.util.Constants;
import com.orange.core.validator.group.Update;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import lombok.experimental.Accessors;
import org.apache.ibatis.type.JdbcType;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName(autoResultMap = true)
public class Coupon implements IIntIdModel<Coupon>, IOperatorModel<Coupon> {

    @NotNull(message = "请求参数不合法", groups = {Update.class})
    @TableId(type = IdType.AUTO)
    private @With Integer id;

    /**
     * 标题
     */
    @NotBlank(message = "请输入标题")
    private String title;

    /**
     * 分类id
     */
    @NotNull(message = "请选择优惠券分类")
    private Integer categoryId;

    /**
     * 商户id
     */
    @NotNull(message = "请选择商户")
    private Integer shopId;

    /**
     * 使用门店
     */
    @TableField(exist = false)
    private String shopName;

    /**
     * 使用门店地址
     */
    @TableField(exist = false)
    private String shopAddress;

    /**
     * 优惠券价值
     */
    @NotNull(message = "请输入优惠金额")
    private BigDecimal couponValue;

    /**
     * 使用门槛，无门槛传0
     */
    @NotNull(message = "请输入使用门槛")
    private BigDecimal useThreshold;

    /**
     * 金额
     */
    @NotNull(message = "请输入支付金额")
    private BigDecimal price;

    /**
     * 标签
     */
    @TableField(typeHandler = JacksonTypeHandler.class, jdbcType = JdbcType.ARRAY)
    private List<String> tags;

    /**
     * icon url
     */
    private String iconUrl;

    /**
     * 门店icon url
     */
    @TableField(exist = false)
    private String shopIconUrl;

    /**
     * 顶部图片
     */
    @TableField(exist = false)
    private List<String> banners;

    /**
     * 有效期开始
     */
    @NotNull(message = "请选择有效期")
    @JsonFormat(pattern = Constants.DEFAULT_DATE_FORMAT)
    private LocalDate effectStart;

    /**
     * 有效期结束
     */
    @NotNull(message = "请选择有效期")
    @JsonFormat(pattern = Constants.DEFAULT_DATE_FORMAT)
    private LocalDate effectEnd;

    /**
     * 库存
     */
    @JsonFormat(pattern = Constants.DEFAULT_DATE_FORMAT)
    private Integer stock;

    /**
     * 上下架状态：0下架，1上架
     */
    @JsonFormat(pattern = Constants.DEFAULT_DATE_FORMAT)
    private Integer shelf;

    /**
     * 使用须知
     */
    @NotBlank(message = "请输入使用须知")
    private String usageNote;

    /**
     * 描述
     */
    @NotBlank(message = "请输入购买须知")
    private String description;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableLogic
    private Long del;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime createTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableField(fill = FieldFill.INSERT)
    private Integer createBy;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime updateTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updateBy;
}
